package designpatterns.factory.abs.code;

import java.util.Objects;

/**
 * 苹果工厂
 */
public class IPhoneFactory implements PhoneAbstractFactory {
    @Override
    public Phone creatPhone(String version) throws RuntimeException {
        System.out.println("获取手机:" + version);
        Phone phone = null;
        switch (version) {
            case "IPHONE_12":
                phone = new IPhone12();
                break;
            case "IPHONE_13":
                phone = new IPhone13();
                break;
        }
        if (Objects.isNull(phone)) {
            throw new RuntimeException("没有这样的手机！");
        }
        return phone;
    }
}
